<fieldset>
    <legend>Customer Information</legend>
    <div id="CustProductHead">
        <?php echo $form->select('CustProduct.customer_id', $customers, null, array('style' => 'margin-right: 10px;')); ?>
    </div>
    <?php if ($mode == 'edit') : ?>
    <div id="custProductSites">
        <ul>
            <?php foreach($sites as $site) : ?>
            <li><?php echo $html->link($site['Site']['name'], array('controller' => 'its_cust_product_sites', 'action' => 'view', 'site_id' => $site['Site']['id'], 'product_id' => $this->data['CustProduct']['product_id']));?></li>
            <?php endforeach; ?>
        </ul>
    </div>
    <?php endif; ?>
</fieldset>

<script type="text/javascript">
<?php if($mode == 'add') : // เรียกหน้า view นี้เมื่อมีการเลือก customer แล้ว ?>
<?php elseif($mode == 'edit') : ?>
    $j(function() { $j("#custProductSites").tabs(tab_options); });
<?php endif; ?>
    // การเรียกหน้า view นี้ครั้งแรก ยังไม่ได้เลือก customer
    $("CustProductCustomerId").observe('change', function() {
        var url = "<?php echo $this->base; ?>/its_cust_products/view/";
        url += "customer_id:" + $F("CustProductCustomerId") + "/";
        url += "product_id:" + <?php echo $this->data['CustProduct']['product_id']; ?> + "/";
        new Ajax.Updater('custProduct', url, { asynchronous:true, evalScripts:true, onComplete:function(request, json) {Element.hide('indicator');}, onLoading:function(request) {Element.show('indicator');}, requestHeaders:['X-Update', 'content']
        });
    })
<?php if($this->layout == 'popup') : ?>
    $("ItsCustProductsForm").observe('submit', function() {
        $j("#popup").dialog('option', 'modal', false);
        $j("#popup").dialog('option', 'modal', true);
    });
<?php endif; ?>
</script>
<?php //debug($this->data); ?>